$(function () {
    addDishes();
    $("#dishesPhoto").css("display","none");
    dishesCheckOut.checkout("#addForm");
});
function addDishes() {
    $('#confirmData').on("click", function () {
        $("#addForm").data("bootstrapValidator").validate();
        if (!$("#addForm").data("bootstrapValidator").isValid()) {
            return false;
        }
        $("#sId").val(localStorage.getItem("sId"));
        let formData = new FormData($("#addForm")[0]);
        $.ajax({
            url: "/dishes",
            method: "POST",
            data: formData,
            cache: false,
            processData: false,
            contentType: false,
            success: (res) => {
                let resp = JSON.parse(res);
                if (resp.msg == "success") {
                    $(".addSuc").show();
                    setTimeout(() => {
                        $(".addSuc").hide();
                    }, 2000);
                    window.location.reload();
                } else {
                    $(".addErr").show();
                    setTimeout(() => {
                        $(".addErr").hide();
                    }, 2000)
                }
            }
        })
    });
}
